package com.cms.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.cms.entity.base.BaseSite;
import com.cms.enums.SiteType;
import com.cms.utils.WebUtils;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Entity -站点
 * 
 * 
 * 
 */
@SuppressWarnings("serial")
@EqualsAndHashCode(callSuper = false)
@TableName("cms_site")
public class Site extends BaseSite {

    /**
     * 获取地址
     */
    public String getUrl(){
        String contextPath = WebUtils.getContextPath();
        if(SiteType.CAT.ordinal()==getType()){
            String cat = getCat(); //目录
            if(StringUtils.isBlank(cat)){
                return contextPath;
            }
            return contextPath+"/"+cat;
        }else if(SiteType.DOMAIN.ordinal()==getType()){
            String protocol = getProtocol(); //协议
            if(StringUtils.isBlank(protocol)){
                protocol = "";
            }
            String domain = getDomain(); //域名
            if(StringUtils.isBlank(domain)){
                domain = "";
            }
            return protocol+domain+contextPath;
        }
        return contextPath;
    }
}
